package com.neuedu.test;

import com.neuedu.Mapper.BooksMapper;
import com.neuedu.po.Books;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {
    public static void main(String[] args) throws IOException {
        try {
            //读取配置文件，获得配置文件信息
            InputStream input = Resources.getResourceAsStream("SqlMapConfig.xml");
            //通过配置信息创建SqlSessionFactory
            SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(input);
            //通过SqlSessionFactory打开数据库会话
            SqlSession sqlSession = ssf.openSession();
            BooksMapper mapper =sqlSession.getMapper(BooksMapper.class);
            List<Books>list=mapper.selectAll();
            for (Books b:list){
                System.out.println(b);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
